package com.zcl.day13_demo7.fragment;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.zcl.day13_demo7.R;
import com.zcl.day13_demo7.adapter.RlvAdapter;
import com.zcl.day13_demo7.bean.InFoBean;
import com.zcl.day13_demo7.bean.contract.HomeContract;
import com.zcl.day13_demo7.bean.presenter.HomePresenter;

public class HomeFragment extends Fragment implements HomeContract.View {
    private RecyclerView recycler;
    private RlvAdapter rlvAdapter;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View inflate = inflater.inflate(R.layout.recycler, container, false);
        initPresenter();
        initView(inflate);
        return inflate;
    }

    private void initPresenter() {
        HomePresenter homePresenter = new HomePresenter(this);
        homePresenter.getData();
    }
    private void initView(View inflate) {
        recycler = (RecyclerView) inflate.findViewById(R.id.recycler);
        recycler.setLayoutManager(new LinearLayoutManager(getActivity()));
        rlvAdapter = new RlvAdapter(getActivity());
        recycler.setAdapter(rlvAdapter);
    }
    @Override
    public void getSuccess(InFoBean bean) {
        rlvAdapter.addData(bean.getResults());
    }

    @Override
    public void getFile(String msg) {
    }


}
